package com.lihepeng.leecode.interview;

public class DeadThreadLock {
    private String lock1 = "lock1";
    private String lock2 = "lock2";

    private class LockA implements Runnable {

        @Override
        public void run() {
            synchronized (lock1) {
                System.out.println("获得锁1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lock2) {
                    System.out.println("获得锁2");

                }
            }
        }
    }

    private class LockB implements Runnable {

        @Override
        public void run() {
            synchronized (lock2) {
                System.out.println("获得锁1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lock1) {
                    System.out.println("获得锁2");

                }
            }
        }
    }
}
